package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.TableClient;
import com.woniuxy.store.client.param.tableParam.AddTableParams;
import com.woniuxy.store.client.param.tableParam.LoadAllStoreTableParams;
import com.woniuxy.store.client.param.tableParam.ModifyTableParams;
import com.woniuxy.table.client.TableMannageClient;
import com.woniuxy.table.client.TableQueryClient;
import com.woniuxy.table.client.param.AddTableParam;
import com.woniuxy.table.client.param.LoadAllStoreTableParam;
import com.woniuxy.table.client.param.ModifyTableParam;
import com.woniuxy.table.client.result.DinnerTableClientDto;
import common.WoniuPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RestController
@RequestMapping("/store/table")
public class TableClientImpl implements TableClient {
    @Autowired
    private TableQueryClient tableQueryClient;
    @Autowired
    private TableMannageClient tableMannageClient;
    @Log("查询餐桌")
    @Override
    public Result loadAllStoreTable(LoadAllStoreTableParams loadAllStoreTableParams) {
        LoadAllStoreTableParam loadAllStoreTableParam = BeanUtil.toBean(loadAllStoreTableParams, LoadAllStoreTableParam.class);
        loadAllStoreTableParam.setStoreId(StoreIdUtil.getFromToken());
        Result<WoniuPage<DinnerTableClientDto>> woniuPageResult = tableQueryClient.loadAllStoreTable(loadAllStoreTableParam);
        return woniuPageResult;
    }
    @Log("添加餐桌")
    @Override
    public Result addTable(AddTableParams addTableParams) {
        AddTableParam addTableParam = BeanUtil.toBean(addTableParams, AddTableParam.class);
        addTableParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = tableMannageClient.addTable(addTableParam);
        return result;
    }
    @Log("修改餐桌状态")
    @Override
    public Result modifyTable(@Valid ModifyTableParams modifyTableParams) throws Exception {
        ModifyTableParam modifyTableParam = BeanUtil.toBean(modifyTableParams, ModifyTableParam.class);
        modifyTableParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = tableMannageClient.modifyTable(modifyTableParam);
        return result;
    }
    @Log("删除餐桌")
    @Override
    public Result deleteTable(Integer tableId) {
        return tableMannageClient.deleteTable(StoreIdUtil.getFromToken(),tableId);
    }

}
